package UnitTestCase;

import java.util.Arrays;

public class PTBac2 {
	// khai bao he so
	private double A, B, C;

	public PTBac2() {
		A = 0;
		B = 0;
		C = 0;
	}

	public PTBac2(int a, int b, int c) {
		super();
		A = a;
		B = b;
		C = c;
	}

	public double getA() {
		return A;
	}

	public void setA(double a) {
		A = a;
	}

	public double getB() {
		return B;
	}

	public void setB(double b) {
		B = b;
	}

	public double getC() {
		return C;
	}

	public void setC(double c) {
		C = c;
	}

	// vo so nghiem = null
	// vo nghiem {}
	// nghiem kep = array[1]
	// 2 nghiem. = array[2]
	public double[] tinhnghiem() {
		if (A == 0) {
			if (B == 0) {
				if (C == 0) {
					return null;
				} else {
					return new double[0];
				}
			}
			else{
				return new double[] { -C / B };
			}
		} else {
			double denta = B * B - 4 * A * C;
			if (denta < 0) {
				return new double[0];
			} else if (denta == 0) {
				return new double[] { -B / (2 * A) };
			} else {
				return new double[] { (-B - Math.sqrt(denta)) / (2 * A),
						(-B + Math.sqrt(denta)) / (2 * A) };
			}
		}
	}

	@Override
	public String toString() {
		return "PTBac2 [A=" + A + ", B=" + B + ", C=" + C + ", tinhnghiem()="
				+ Arrays.toString(tinhnghiem()) + "]";
	}
}
